//
//  TBCVideoTableViewCell.m
//  待定
//
//  Created by dllo on 15/11/6.
//  Copyright © 2015年 BoyaLee. All rights reserved.
//

#import "TBCVideoTableViewCell.h"
#import <UIImageView+WebCache.h>
@implementation TBCVideoTableViewCell

@synthesize imageView;

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubview];
    }
    return self;
}


-(void)createSubview
{
    
    self.userImageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 40, 40)];
    //self.userImageView.backgroundColor = [UIColor redColor];
    [self addSubview:self.userImageView];
    
    self.nameLabel = [[BaseLabel alloc] initWithFrame:CGRectMake(60, 10, 200*WIDTHSUIT, 40)];
    //self.nameLabel.backgroundColor = [UIColor greenColor];
    [self addSubview:self.nameLabel];
    
    
    self.category_nameLabel = [[BaseLabel alloc] initWithFrame:CGRectMake(280*WIDTHSUIT, 10, 80, 40)];
    //self.category_nameLabel.backgroundColor = [UIColor redColor];
    self.category_nameLabel.textAlignment = NSTextAlignmentRight;
    [self addSubview:self.category_nameLabel];
    
    
    self.titleLabel = [[BaseLabel alloc] initWithFrame:CGRectMake(20, 60*HEIGHTSUIT, 340*WIDTHSUIT, 40)];
    //self.titleLabel.backgroundColor = [UIColor yellowColor];
    [self addSubview:self.titleLabel];
    
    self.imageView = [[UIImageView alloc] init];
    //self.imageView.backgroundColor = [UIColor lightGrayColor];
    [self addSubview:self.imageView];
    
    self.playImageView = [[UIImageView alloc] init];
    //self.playImageView.backgroundColor = [UIColor clearColor];
    self.playImageView.image = [UIImage imageNamed:@"play.png"];
    [self.imageView addSubview:self.playImageView];
}

-(void)setVideo:(TBCVideo *)video
{
    _video = video;
    [self.imageView sd_setImageWithURL:[NSURL URLWithString:video.url] placeholderImage:[UIImage imageNamed:@"PlaceHolderImage@2x"]];
    [self.userImageView sd_setImageWithURL:[NSURL URLWithString:video.avatar_url] placeholderImage:[UIImage imageNamed:@"PlaceHolderImage@2x"]];
    self.nameLabel.text = video.name;
    self.category_nameLabel.text = video.category_name;
    if (![video.title isEqualToString:@""]) {
        self.titleLabel.text = video.title;
    }
    else
    {
        self.titleLabel.text = @"暂无标题";
    }
    
    NSString *stringHeight = video.video_height;
    NSString *stringWidth = video.video_width;
    self.imageView.frame = CGRectMake(10, 110*HEIGHTSUIT, 350*WIDTHSUIT, stringHeight.integerValue * (350*WIDTHSUIT) / stringWidth.integerValue + 20);
    self.playImageView.frame = CGRectMake(140*WIDTHSUIT, self.imageView.frame.size.height/2-20, 60, 60);
    self.playImageView.layer.masksToBounds = YES;
    self.playImageView.layer.cornerRadius = self.playImageView.frame.size.width/2;
    self.playImageView.alpha = 0.8;
    
}


@end
